﻿using Md.Api.Entity.ModelDB;

namespace Md.Petapoco.Repositories.MdTrainingEducation;
/// <summary>
/// 用户和角色关联仓储
/// </summary>
public class SysUserRoleRep : BaseRep<SysUserRoleModel>
{
    /// <summary>
    /// 通过用户编号获取(系统用户角色关联)列表
    /// </summary>
    /// <param name="userId">用户编号</param>
    /// <returns>IEnumerable<SysUserRoleModel></returns>
    public IEnumerable<SysUserRoleModel> GetSysUserRoleListByUserId(long userId)
    {
        #region ===sql===
        string sqlStr = string.Format(@"
            select `id`
                  ,`user_id`
                  ,`role_id`
            from `sys_user_role`
            where 1 = 1 and `user_id` = @0
         ");
        #endregion

        return MdTrainingEducationDB.GetInstance().Query<SysUserRoleModel>(sqlStr, userId);
    }
    /// <summary>
    /// 通过用户编号删除(系统用户角色关联)数据
    /// </summary>
    /// <param name="userId">用户编号</param>
    /// <returns>int</returns>
    public int DeleteRoleByUserId(long userId)
    {
        string strSql = string.Format(@"
            where 1 = 1 and `user_id` = @0
        ");

        return MdTrainingEducationDB.GetInstance().Delete<SysUserRoleModel>(strSql, userId);
    }
}

